package fr.orleans.publique;

import java.util.ArrayList;
import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.model.SelectItem;

import entities.Tournament;
import fr.orleans.tools.JSFServices;
import fr.orleans.tools.ManagedBeans;

@ManagedBean
@ViewScoped
public class ChoiceTournament extends ManagedBeans{

	private List<SelectItem> listTournament;
	private Tournament tournamentSelected;
	
	public ChoiceTournament(){
		
	}

	public List<SelectItem> getListTournament() {
		if(this.listTournament == null){
			List<Tournament> listTmp = this.getService().getWebAction().getListTournamentByFlagActivated();
			
			this.listTournament = new ArrayList<SelectItem>();
			
			for(Tournament t : listTmp){
				this.listTournament.add(new SelectItem(t, t.getName()));
			}
		}
		return listTournament;
	}

	public void setListTournament(List<SelectItem> listTournament) {
		this.listTournament = listTournament;
	}

	public Tournament getTournamentSelected() {
		return tournamentSelected;
	}

	public void setTournamentSelected(Tournament tournamentSelected) {
		this.tournamentSelected = tournamentSelected;
	}	
	
	public String goToDetailTournament(){
		JSFServices.putParameterInRequestMap("tournament", this.tournamentSelected);
		return "/modules/public/detailTournament.jsf";
	}
}